package org.gw.ylc.base.service;

import org.gw.ylc.base.model.Major;
import org.gw.ylc.base.repositories.MajorRepository;
import org.gw.ylc.base.util.PermissionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MajorService {
	@Autowired
	private MajorRepository majorRepository;
	
	private static MajorService INSTANCE;
	
	public MajorService(){
		INSTANCE = this;
	}
	
	public static MajorService getINSTANCE() {
		return INSTANCE;
	}
	
	@Cacheable(value = "common.Major",key="#id")
	public Major findById(String id) {
		return majorRepository.findOne(id);
	}
	
	public List<Major> findByDepartment(String department) {
		return majorRepository.findByDepartment(PermissionUtil.getFilteredDepartmentId(department));
	}
}
